
<?= HTML::style('static/nicevalidator/jquery.validator.css')?>

<h3 class="page-header">添加城市</h3>

<form action="<?= URL::curr()?>" method="post" autocomplete="off" class="col-sm-6 col-md-4 ajax-submit">
	
	<div class="form-group">
		<input class="form-control" type="hidden" id="province" name="province" placeholder="省份"  value="" required >
	</div>
	
	<div class="form-group">
		<select class="form-control" name="city" onclick="getSelect()" id="sele">
			<option value="" disabled>选择城市</option>
			<?php foreach ($city as $key=>$value):?>
			<option disabled><?= $key?></option>
				<?php foreach ($value as $k=>$v):?>
			<option data-pro="<?= $key?>" data-code="<?= $k?>" value="<?= $v?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?= $v?></option>
				<?php endforeach;?>
			<?php endforeach;?>
        </select>
	</div>
	
	<div class="form-group">
		<input class="form-control" type="text" id="city_code" name="city_code" placeholder="城市码" value="" required >
	</div>
	
	
	
	<div class="form-group">
		<button type="submit" class="btn btn-info">提交</button>
	</div>
</form>


<?= HTML::script('static/nicevalidator/jquery.validator.min.js?local=zh-CN')?>
<?= HTML::script('static/js/jquery-1.12.4.min.js')?>
<script type="text/javascript">	
// 	$(function(){
		
// 		$('#city_code').change(function(){
// 			var city_code = attr('data-code');
// 			alert(111);
// 		})
// 	})

	function getSelect()
	{
	    var obj = document.getElementById("sele");
	    var index=obj.selectedIndex;
	    var a=obj.options[index].getAttribute("data-code"); 
// 	    alert(a);
	    document.getElementById('city_code').value=a;
	    getProvince();
	}

	function getProvince()
	{
		var obj = document.getElementById("sele");
	    var index=obj.selectedIndex;
	    var province=obj.options[index].getAttribute("data-pro"); 
// 	    alert(province);
	    document.getElementById('province').value=province;
	}
</script>
